// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package action.paiement;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.mail.internet.InternetAddress;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import bean.client.Client;

public class LogicWebPaiementExterieur
{
    private static Log logger = LogFactory.getLog(action.paiement.LogicWebPaiementExterieur.class);
    private static final String NOM_CLASSE_COMPLET = LogicWebPaiementExterieur.class.getName();
    private static final String NCC = NOM_CLASSE_COMPLET;
    private static final String NOM_CLASSE = NOM_CLASSE_COMPLET.substring(NOM_CLASSE_COMPLET.lastIndexOf('.') + 1);
    public static Hashtable s_beanEtudiantsPaiementExterieur = new Hashtable();

    public static StringBuffer paiementExterieur(HttpServletRequest httpservletrequest, int NumTransaction, int montant)
        throws IOException, InterruptedException
    {
		ResourceBundle properties = ResourceBundle.getBundle("ressources");
		
		System.out.println("je suis dans le paiement");
		
        String s = System.getProperty("file.separator");
        //String s1 = (new StringBuilder()).append(httpservletrequest.getSession().getServletContext().getRealPath("/")).append("WEB-INF").append(s).append("cgi").append(s).append(properties.getString("paiement.nomCgi")).append(" ").toString();
        
                
        String s1 = (new StringBuilder()).append("C:\\worspace\\testPaiementCB\\WebContent\\WEB-INF\\cgi-bin").append(s).append(properties.getString("paiement.nomCgi")).append(" ").toString();
       
        /*Calendar calendar = Calendar.getInstance();
        Enumeration enumeration = properties.getKeys();
        Object obj = null;
       
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Object obj1 = enumeration.nextElement();
            if(((String)obj1).startsWith("paiement") && !"nomCgi".equals(((String)obj1).substring(9)) && !"cleMontant".equals(((String)obj1).substring(9)) && !"cleCommande".equals(((String)obj1).substring(9)) && !"cleRetour".equals(((String)obj1).substring(9)) && !"cleAutorisation".equals(((String)obj1).substring(9)) && !"cleTransaction".equals(((String)obj1).substring(9)) && !"cleEmail".equals(((String)obj1).substring(9)) && !"cleMontant1".equals(((String)obj1).substring(9)) && !"cleMontant2".equals(((String)obj1).substring(9)) && !"cleDate1".equals(((String)obj1).substring(9)) && !"cleDate2".equals(((String)obj1).substring(9)))
                s1 = (new StringBuilder()).append(s1).append(obj1.toString().substring(9)).append("=").append(properties.getString((String)obj1)).append(" ").toString();
        } while(true);
        beanetudiant.setDateReferencePaiementExt(System.currentTimeMillis());*/
        HttpSession httpsession = httpservletrequest.getSession();
        String s2=null;
       // String s2 = (String)httpsession.getAttribute("ref_etu");
        
        Object objClient = httpsession.getAttribute("client");
        Client client = (Client)objClient;
        
        
        String module;
        module=properties.getString("appserver.home");
    
        String adrRetourOK;
        adrRetourOK=properties.getString("paiement.IBS_EFFECTUE");
        
        String adrRetourKO;
        adrRetourKO=properties.getString("paiement.IBS_REFUSE");
        
        String adrRetourAN;
        adrRetourAN=properties.getString("paiement.IBS_ANNULE");
       
        String PBX_BACK1,PBX_BACK2,PBX_BACK3;
        PBX_BACK1=properties.getString("paiement.PBX_PAYBOX");
        PBX_BACK2=properties.getString("paiement.PBX_BACKUP1");
        PBX_BACK3=properties.getString("paiement.PBX_BACKUP2");
        
        String IBS_SIT;
        IBS_SIT=properties.getString("paiement.IBS_SITE");
        
        
       // s1 = (new StringBuilder()).append(s1).append(" cleErreur=").append(properties.getString("paiement.cleErreur")));
        
        
        /*
        s1 = (new StringBuilder()).append(s1).append(properties.getString("paiement.cleMontant").trim()).append("=").append(montant*100).append(" ").toString();       
        s1 = (new StringBuilder()).append(s1).append(" PBX_PAYBOX=https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi ").toString();
        s1 = (new StringBuilder()).append(s1).append(" PBX_BACKUP1=https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi ").toString();
        s1 = (new StringBuilder()).append(s1).append(" PBX_BACKUP2=https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi ").toString();        
        s1 = (new StringBuilder()).append(s1).append(" PBX_PORTEUR="+client.getEmail()).toString();
        s1 = (new StringBuilder()).append(s1).append(" PBX_TOTAL="+montant*100).toString();
        s1 = (new StringBuilder()).append(s1).append(" PBX_CMD="+NumTransaction).toString();
        */
            
           
        try
        {
        	
        	//System.out.println(s1);
        	s1= module + " cleErreur=err IBS_MODE=4 PBX_BACKUP2="+PBX_BACK3+" PBX_BACKUP1="+PBX_BACK2+" IBS_RETOUR=ref:R;trans:T;auto:A;tarif:M;err:E IBS_EFFECTUE="+adrRetourOK+" IBS_DEVISE=978 IBS_ANNULE="+adrRetourAN+" PBX_IDENTIFIANT=2 PBX_RANG=99 PBX_PAYBOX="+PBX_BACK1+" IBS_REFUSE="+adrRetourKO+" cleSite1=PBX_PAYBOX cleSite3=PBX_BACKUP2 cleSite2=PBX_BACKUP1 IBS_SITE="+IBS_SIT+" PBX_PORTEUR="+client.getEmail().toString()+" PBX_TOTAL="+(montant*100)+" PBX_CMD="+NumTransaction;
        	System.out.println(s1);
            Process process = Runtime.getRuntime().exec(s1);
            logger.debug("Runtime.getRuntime().exec appel\351 ...");
            StringBuffer stringbuffer = new StringBuffer();
            InputStreamReader inputstreamreader = new InputStreamReader(process.getInputStream());
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
            for(String s4 = null; (s4 = bufferedreader.readLine()) != null;)
                stringbuffer.append(s4);

            logger.debug("Appel du wait for ");
            int i = process.waitFor();
            logger.debug((new StringBuilder()).append("Find du wait for _ Process exitValue = ").append(i).toString());
            return stringbuffer;
        }
        catch(Throwable throwable)
        {
            throwable.printStackTrace();
        }
        return null;
    }


}
